package com.maigao.entity.jpa;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

@Data
@Entity
@Table(name = "tb_student_course")
@DynamicInsert
@DynamicUpdate
public class StudentCourse implements Serializable {

    public enum Status {
        NORMAL(0), DISABLED(-1);

        Status(int value) {
            this.value = value;
        }

        private int value;

        public int getValue() {
            return value;
        }

        public static Status getByValue(int value) {
            Optional<Status> optional = Arrays.stream(values()).filter(p -> Objects.equals(p.getValue(), value)).findFirst();
            if (optional.isPresent()) {
                return optional.get();
            }
            return null;
        }
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "student_id")
    private Integer studentId;

    @Column(name = "student_name")
    private String studentName;

    @Column(name = "course_type")
    private String courseType;

    @Column(name = "course_note")
    private String courseNote;

    @Column(name = "total_count")
    private int totalCount;

    @Column(name = "remain_count")
    private int remainCount;

    @Column(name = "gift_count")
    private int giftCount;

    @Column(name = "total_price")
    private BigDecimal totalPrice;

    @Column(name = "unit_price")
    private BigDecimal unitPrice;

    @Column(name = "create_time")
    private LocalDateTime createTime;

    @Column(name = "last_update_time")
    private LocalDateTime lastUpdateTime;

    @Column(name = "status")
    private Integer status;
}
